<template>
  <div>
    <!-- 定义属性值 -->
    <MyHeader title="购物车案例" color="aqua" bgc="green"></MyHeader>
    <div class="main">
      <!-- v-for遍历list数组，把值传给子组件 -->
    <MyGoods v-for="item in list" :key="item.id" :good="item"></MyGoods>
    </div>
    <!-- 把list数组传入子组件 -->
    <MyFooter :list="list"></MyFooter>
  </div>
</template>

<script>
// 引入子组件
import MyHeader from "./components/MyHeader.vue"
import MyGoods from "./components/MyGoods.vue"
import MyFooter from "./components/MyFooter.vue"
// 引用axios
import axios from "axios"
export default {
  data() {
    return {
      // 定义空数组接取数据
      list: []
    }
  },
  components: {
    MyHeader,
    MyGoods,
    MyFooter
  },
  // 用axios请求数据
  created() {
    axios({
      url: '/api/cart'
    }).then(res => {
      console.log(res)
      this.list = res.data.list
    }).catch(err => {
      console.log(err)
    })
  }
}
</script>

<style>
.main {
  padding-top: 45px;
  padding-bottom: 50px;
}
</style>